<?php

namespace Home\Controller;

class HintController extends HomeCoreController {
	
    public $Model = null;

    protected function _initialize(){
		
        parent::_initialize();
		
        $this->Model = D('Hint');
		
    }
	
	public function add(){
		
		if(IS_POST){
			
			$post_data = I('post.');
			
			$data = $this->Model->create($post_data);
			
			if($data){
				
				$result = $this->Model->update($data);
					
				if($result){
					
					echo json_encode(array('info'=>'操作成功', 'status'=>'y', 'id'=>$result));
												
				}else{
						
					$error = $this->Model->getError();
						
					echo json_encode(array('info'=>$error, 'status'=>'n'));
						
				}
					
			}else{
					
				$error = $this->Model->getError();
					
				echo json_encode(array('info'=>$error, 'status'=>'n'));
					
			}
												
		}else{
						
			$this->display();
			
		}
		
	}
	
	public function edit(){
		
		if(IS_POST){
			
			$post_data = I('post.');
			
			$map['id'] = $post_data['zid'];
			
			$post_data['end_time'] = time();
						
			$data = $this->Model->create($post_data);
			
			if($data){
				
				$result = $this->Model->where($map)->save($data);
					
				if($result){

					echo json_encode(array('info'=>'操作成功', 'status'=>'y'));
												
				}else{
						
					$error = $this->Model->getError();
						
					echo json_encode(array('info'=>$error, 'status'=>'n'));
						
				}
					
			}else{
					
				$error = $this->Model->getError();
					
				echo json_encode(array('info'=>$error, 'status'=>'n'));
					
			}
												
		}else{
						
			$this->display();
			
		}
		
	}
		
}